<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Controller;
use OT\DataDictionary;

/**
 * 前台首页控制器
 * 主要获取新闻页面详情
 */
class NewsController extends HomeController {

	//新闻首页
    public function index(){
//        $this->assign('page',D('Document')->page);//分页

        //头部数据
        $wherenav=array(
            'language' => 0,
            'parentid' => 0
        );
        $nav=M('navigator')
            ->where($wherenav)
            ->order('sort')
            ->select();
        foreach ($nav as $key=>$value){
            $nav[$key]['list']=M('navigator')->where(array('parentid'=>$value['id']))->select();
        }
        $this->assign('nav',$nav);
        //头部数据
        //banner
        $banner=M('otherbanner')
            ->where(array('path'=>'/News/index'))
            ->find();
        $this->assign('banner',$banner['pictureid']);
        //banner

        //获取类别及列表内容
        $category[1]['name']=M('newscategory')
                ->where(array('id'=>1))
                ->getfield('name');
        $category[1]['list']=M('news')
                ->where(array('category'=>1))
                ->field('id,title,time,coverid')
                ->limit(6)
                ->select();
        $category[2]['name']=M('newscategory')
            ->where(array('id'=>2))
            ->getfield('name');
        $category[2]['list']=M('news')
            ->where(array('category'=>2))
            ->field('id,title,time,coverid')
            ->limit(6)
            ->select();
        $category[3]['name']=M('newscategory')
            ->where(array('id'=>3))
            ->getfield('name');
        $category[3]['list']=M('news')
            ->where(array('category'=>3))
            ->field('id,title,time,content')
            ->limit(6)
            ->select();

        $this->assign('cate',$category);
        $this->assign('empty1','<li><a>暂无数据</a></li>');
        $this->assign('empty2','<div class="z1"><text>--/--</text></div><div class="z2"><text>----</text></div><div class="z3"><a href="#">暂无数据</a></div><div class="z4"><a href="#">暂无数据</a></div>');
        //获取类别及列表内容

//        var_dump($category);exit;
        $this->display();
    }
    public function showbyid(){
        $newsid=I('get.id');

        $data=M('news')
            ->where(array('id'=>$newsid))
            ->find();
        $category=M('newscategory')->where(array('id'=>$data['category']))->find();
        $data['category']=$category['name'];
        $pre=M('news')
            ->where(array('id'=>array('lt',$newsid)))
            ->field('id,title')
            ->order('id desc')
            ->find();
        $next=M('news')
            ->where(array('id'=>array('gt',$newsid)))
            ->field('id,title')
            ->find();
        $this->assign('data',$data);
        $this->assign('pre',$pre);
        $this->assign('next',$next);

        //头部数据
        $wherenav=array(
            'language' => 0,
            'parentid' => 0
        );
        $nav=M('navigator')
            ->where($wherenav)
            ->order('sort')
            ->select();
        foreach ($nav as $key=>$value){
            $nav[$key]['list']=M('navigator')->where(array('parentid'=>$value['id']))->select();
        }
        $this->assign('nav',$nav);
        //头部数据
        //banner
        $banner=M('otherbanner')
            ->where(array('path'=>'/News/index'))
            ->find();
        $this->assign('banner',$banner['pictureid']);
        //banner
        $this->display();
    }

}